package com.xinchao.core.config;

import java.util.concurrent.Executor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 异步设置
 *
 * @author linqiang
 * @date 2018-07-18 11:07
 */
@Configuration
@EnableAsync
public class AsyncConfig {
	@Value("${xc.async-core-pool-size}")
    private Integer corePoolSize;
	@Value("${xc.async-max-pool-size}")
    private Integer maxPoolSize;
	@Value("${xc.async-queue-capacity}")
    private Integer queueCapacity;
	@Value("${xc.async-keep-alive-time}")
    private Integer keepAliveSeconds;

    @Bean
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.setKeepAliveSeconds(keepAliveSeconds);
        executor.initialize();
        return executor;
    }

}
